﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

using Thrift.Protocol;
using Thrift.Transport;

using Storm;

namespace Monitor.Core.Sensor
{
    class StormNimbusSensor : AbstractSensor
    {
        public StormNimbusSensor(int id, Uri uri)
            : base(id, uri)
        {
        }

        protected override ServiceStatus PingService()
        {
            var ep = new DnsEndPoint(_uri.Host, _uri.Port);
            using (var _socket = new TSocket(ep.Host, ep.Port))
            {
                var _transport = new TFramedTransport(_socket);
                var protocol = new TBinaryProtocol(_transport);
                Nimbus.Client n = new Nimbus.Client(protocol);

                _socket.Open();
                _summary = n.getClusterInfo();
                _socket.Close();
            }

            return ServiceStatus.Alive;
        }

        private ClusterSummary _summary;
        public ClusterSummary Summary
        {
            get { return _summary; }
        }
    }
}
